<%@ page session="false" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://myfaces.apache.org/trinidad" prefix="tr"%>
<%@taglib uri="http://myfaces.apache.org/trinidad/html" prefix="trh"%>
<tr:panelGroupLayout rendered="#{not empty orderBean.number}"
	partialTriggers="addCommentButton saveCommentButton cancelAddComment">
	<fieldset><legend>Lista komentarzy</legend>
	
 	<tr:panelGroupLayout rendered="#{not SessionDataTO.readOnly}">
		<tr:commandLink shortDesc="Zapisz komentarz" 
			disabled="#{SessionDataTO.readOnly}"
			rendered="#{not empty commentBean}" inlineStyle="margin-right:5px"
			action="#{orderController.saveComment}"
			partialSubmit="true" id="saveCommentButton">
				<tr:image source="gfx/save_button.png" />
		</tr:commandLink>
		<tr:commandLink shortDesc="Anuluj dodawanie" immediate="true"
			disabled="#{SessionDataTO.readOnly}"
			rendered="#{not empty commentBean}"
			actionListener="#{orderController.cancelAddComment}"
			partialSubmit="true" id="cancelAddComment" >
				<tr:image source="gfx/delete32.png" />
		</tr:commandLink>
		<tr:commandLink shortDesc="Dodaj komentarz" immediate="true"
			rendered="#{empty commentBean}" disabled="#{SessionDataTO.readOnly}"
			actionListener="#{orderController.addEmptyComment}"
			partialSubmit="true" id="addCommentButton" >
				<tr:image source="gfx/add32.png" />
		</tr:commandLink>

		<tr:inputText columns="100" rows="10"
			rendered="#{not empty commentBean}" id="commentNote"
			value="#{commentBean.note}" label="Treść:" maximumLength="3024"
			requiredMessageDetail="Podaj komentarz" required="true"
			showRequired="false">
			<tr:message for="commentNote" styleClass="validation_info" />
		</tr:inputText>
	</tr:panelGroupLayout>
	<table width="100%" cellpadding="3" cellspacing="0" style="margin-top:10px; border: 1px solid #ccc">
		<tr style="background-color: #eee;">
			<td>treść</td>
			<td>dodał</td>
			<td>czas</td>
			<td width="20">usuń</td>
		</tr>
		<tr:iterator value="#{orderBean.commentList}" var="comment" rows="0"
					binding="#{orderController.commentIterator}"
					rendered="#{not empty orderBean.commentList}">
			<tr onMouseOver="this.style.backgroundColor='#e0ffc2'" onMouseOut="this.style.backgroundColor='#FFF'">
				<td style="border-top: 1px solid #ccc">
				<tr:outputFormatted value="#{comment.note}">
					<f:converter converterId="FormatedTextConverter" />
				</tr:outputFormatted>
				</td>
				<td style="border-top: 1px solid #ccc">
					<h:outputText value="#{comment.salesmanID}" />
				</td>
				<td style="border-top: 1px solid #ccc">
				<tr:outputText value="#{comment.registrationDate}">
					<f:convertDateTime pattern="dd-MMMMM-yyyy HH:mm (EEEEE)" locale="pl_PL" />
				</tr:outputText>
				</td>
				<td style="border-top: 1px solid #ccc">
					<tr:commandLink shortDesc="Usuń"
								actionListener="#{orderController.commentRemove}"
								rendered="#{currentUserTO.currentSalesman.permissionMap.COMMENT_REMOVE and
								not SessionDataTO.readOnly}"
								onclick="return confirmMessageBox('Czy chcesz usunąć ten komentarz?');">
							<tr:image source="gfx/delete.png" />
					</tr:commandLink>
				</td>
			</tr>
		</tr:iterator>
	</table>
	</fieldset>
</tr:panelGroupLayout>